package org.jetlinks.demo.protocol.siterwell.tcp.message;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.jetlinks.demo.protocol.siterwell.tcp.util.ByteUtils;

/**
 * 添加设备
 * 网关发往平台的消息数据
 */
@Getter
@Setter
@NoArgsConstructor
public class D2SAddDevice extends AbstractCommandRequest {

    private String childDeviceId;
    private String roomNo;

    public static D2SAddDevice of(byte[] data) {
        D2SAddDevice message = new D2SAddDevice();
        message.fromBytes(data, 0);
        return message;
    }


    @Override
    protected void parseData() {
        String hexDataSource = this.getHexDataSource();
        this.childDeviceId = ByteUtils.subHexStrByByte(hexDataSource, 0, 3);
        this.roomNo = ByteUtils.subHexStrByByte(hexDataSource, 3, 5);

    }


    @Override
    public String toString() {
        return "{ add device : " +
                "childDeviceId=" + childDeviceId +
                ", roomNo=" + roomNo +
                '}';
    }
}
